<?php

namespace app\base\controller\api;

use think\admin\Controller;
use app\base\model\RedianTask;
use app\base\model\RedianData;
use app\base\controller\api\Auth;
use app\base\service\TophubdataService;
use app\base\service\AlibailianService;
use app\base\service\HeygenService;
use app\base\service\HuoshanService;
use app\base\service\MinimaxService;
use app\base\service\SimilarityService;
use app\base\service\TaskService;

/**
 * 任务接口
 * Class Login
 * @package app\store\controller
 */
class Task20250505 extends Auth
{
    //统计任务数据
    public function count()
    {
        //总任务数
        $count = RedianTask::mk()->where(['user_id'=>$this->user_id])->count();
        //已完成任务数
        $complete_count = RedianTask::mk()->where(['user_id'=>$this->user_id])->where('progress',6)->count();
        //执行中任务数
        $doing_count = RedianTask::mk()->where(['user_id'=>$this->user_id])->where('progress',"<>",6)
            ->where('progress',"<>",0)->where('error_status',0)->count();
        $this->success('获取成功', ['count'=>$count,'complete_count'=>$complete_count,'doing_count'=>$doing_count]);

    }

    //API配置校验
    public function apiConfigCheck()
    {
        $apiConfig = $this->app->db->name('ai_api_config')->where(['user_id'=>$this->user_id])->column('type');
       // dump($this->user);
        if($this->user['api_config_type']==1){
            if(!in_array(4,$apiConfig)){
                $this->error('请先配置HeyGen API参数');
            }
        }else{
            if(empty($apiConfig)){
                $this->error('请先配置API参数');
            }else if(!in_array(1,$apiConfig)){
                $this->error('请先配置榜眼数据API参数');
            }else if(!in_array(2,$apiConfig)){
                $this->error('请先配置阿里百炼API参数');
            }else if(!in_array(4,$apiConfig)){
                $this->error('请先配置HeyGen API参数');
            }else if(!in_array(6,$apiConfig)) {
                $this->error('请先配置MinMax API参数');
            }
        }
        $voice = $this->app->db->name('ai_voice')->where(['user_id'=>$this->user_id,'platform_name'=>"MINIMAX",'type'=>1])->count();
        if($voice<=0){
            $this->error('请先配置音频模板',null,2);
        }
        $video = $this->app->db->name('ai_voice')->where(['user_id'=>$this->user_id,'platform_name'=>"HeyGen",'type'=>2])->count();
        if($video<=0){
            $this->error('请先配置视频模板',null,3);
        }

        $this->success('校验成功');

    }

    //创建采集任务
    public function create()
    {
        $post_data = $this->app->request->post();
        $save_data = [
            'title'=>$post_data['taskName'],
            'keywords'=>$post_data['keywords'],
            'num'=>$post_data['count'],
            'code'=>"TD".date('YmdHis').rand(1000,9999),
            'system_prompt'=>$post_data['systemPrompt'],
            'user_prompt'=>$post_data['userPrompt'],
            'out_num'=>$post_data['outCount'],
            'audio_platform'=>$post_data['selectedAudioPlatform'],
            'voice'=>$post_data['selectedVoice'],
            'voice_model'=>$post_data['selectedVoiceModel'],
            'video_platform'=>$post_data['selectedVideoPlatform'],
            'video'=>$post_data['selectedVideo'],
            'text_select'=>$post_data['textSelect'],
            'user_id'=>$this->user_id,
            'type'=>$post_data['type'],
            'is_auto_fb'=>$post_data['is_auto_fb'],
            'is_auto_jjjb'=>$post_data['is_auto_jjjb'],
            'is_auto_fbjb'=>$post_data['is_auto_fbjb'],
            'schedule_value'=>$post_data['schedule_value'],
            'total_count'=>$post_data['total_count'],
            'star_time'=>$post_data['date_ragne'][0],
            'end_time'=>$post_data['date_ragne'][1],
        ];
        if(isset($post_data['schedule']) && $post_data['is_auto_fb']==1){
            $save_data['push_schedule'] = json_encode($post_data['schedule']);
        }

        $task_id = RedianTask::mk()->insertGetId($save_data);
        if(isset($post_data['schedule']) && $post_data['is_auto_fb']==1){
            $schedule = $post_data['schedule'];
            foreach ($schedule as $v){
                $run_script = [];
                if($post_data['is_auto_jjjb']==1){
                    $run_script[]=$this->app->db->name("script_confg")->where('type',0)->value('id');
                }
                if($post_data['is_auto_fbjb']==1){
                    $run_script[]=$this->app->db->name("script_confg")->where('type',$v['platform'])->value('id');
                }
                if($v['schedule_type']==2){
                    foreach ($v['target_device'] as $v2){
                        $save_schedule = [
                            'schedule_value'=>$v['schedule_value']*60,
                            'schedule_type'=>$v['schedule_type'],
                            'push_num'=>$v['push_num'],
                            'target_device'=>$v2,
                            'task_id'=>$task_id,
                            'user_id'=>$this->user_id,
                            'platform'=>$v['platform'],
                            'status'=>0,
                            'is_auto_jjjb'=>$post_data['is_auto_jjjb'],
                            'is_auto_fbjb'=>$post_data['is_auto_fbjb'],
                            'run_script'=>json_encode($run_script)

                        ];
                        $this->app->db->name('redian_push_schedule')->insert($save_schedule);
                    }
                }else{
                    foreach ($v['target_device'] as $v2){
                        foreach ($v['schedule_time'] as $v3){
                            $save_schedule = [
                                'schedule_value'=>implode(',',$v3['time']),
                                'schedule_type'=>$v['schedule_type'],
                                'push_num'=>$v3['push_num'],
                                'target_device'=>$v2,
                                'task_id'=>$task_id,
                                'user_id'=>$this->user_id,
                                'platform'=>$v['platform'],
                                'status'=>0,
                                'is_auto_jjjb'=>$post_data['is_auto_jjjb'],
                                'is_auto_fbjb'=>$post_data['is_auto_fbjb'],
                                'run_script'=>json_encode($run_script)
                            ];
                            $this->app->db->name('redian_push_schedule')->insert($save_schedule);
                        }
                    }
                }
            }
        }

       // dump($schedule);exit;

        $this->success('创建成功',$task_id);
    }


    //解析自定义口播文本
    public function parseExcel()
    {
        $file_url = $this->app->request->post('file_url');
        $excel_data = TaskService::instance()->parseExcel($file_url);
        if(empty($excel_data)){
            $this->error('解析失败');
        }
        if(!is_array($excel_data)){
            $this->error($excel_data);
        }
        unset($excel_data[0]);
        $data = array_values($excel_data);
        $this->success("解析成功,共解析出".count($data)."条数据",$data);

    }

    //创建自定义口播文案任务
    public function createZdy()
    {
        $post_data = $this->app->request->post();
        $save_data = [
            'title'=>$post_data['taskName'],
            'code'=>"TD".date('YmdHis').rand(1000,9999),
            'audio_platform'=>$post_data['selectedAudioPlatform'],
            'voice'=>$post_data['selectedVoice'],
            'voice_model'=>$post_data['selectedVoiceModel'],
            'video_platform'=>$post_data['selectedVideoPlatform'],
            'video'=>$post_data['selectedVideo'],
            'text_select'=>$post_data['textSelect'],
            'type'=>$post_data['type'],
            'user_id'=>$this->user_id,
            'file_path'=>$post_data['file_path'],
        ];
        if(isset($post_data['schedule']) && $post_data['is_auto_fb']==1){
            $save_data['push_schedule'] = json_encode($post_data['schedule']);
        }
        $task_id = RedianTask::mk()->insertGetId($save_data);
        if(isset($post_data['schedule'])){
            $schedule = $post_data['schedule'];
            foreach ($schedule as $v){
                $run_script = [];
                if($post_data['is_auto_jjjb']==1){
                    $run_script[]=$this->app->db->name("script_confg")->where('type',0)->value('id');
                }
                if($post_data['is_auto_fbjb']==1){
                    $run_script[]=$this->app->db->name("script_confg")->where('type',$v['platform'])->value('id');
                }
                if($v['schedule_type']==2){
                    foreach ($v['target_device'] as $v2){
                        $save_schedule = [
                            'schedule_value'=>$v['schedule_value']*60,
                            'schedule_type'=>$v['schedule_type'],
                            'push_num'=>$v['push_num'],
                            'target_device'=>$v2,
                            'task_id'=>$task_id,
                            'user_id'=>$this->user_id,
                            'platform'=>$v['platform'],
                            'status'=>0,
                            'is_auto_jjjb'=>$post_data['is_auto_jjjb'],
                            'is_auto_fbjb'=>$post_data['is_auto_fbjb'],
                            'run_script'=>json_encode($run_script)
                        ];
                        $this->app->db->name('redian_push_schedule')->insert($save_schedule);
                    }
                }else{
                    foreach ($v['target_device'] as $v2){
                        foreach ($v['schedule_time'] as $v3){
                            $save_schedule = [
                                'schedule_value'=>implode(',',$v3['time']),
                                'schedule_type'=>$v['schedule_type'],
                                'push_num'=>$v3['push_num'],
                                'target_device'=>$v2,
                                'task_id'=>$task_id,
                                'user_id'=>$this->user_id,
                                'platform'=>$v['platform'],
                                'status'=>0,
                                'is_auto_jjjb'=>$post_data['is_auto_jjjb'],
                                'is_auto_fbjb'=>$post_data['is_auto_fbjb'],
                                'run_script'=>json_encode($run_script)
                            ];
                            $this->app->db->name('redian_push_schedule')->insert($save_schedule);
                        }
                    }
                }
            }
        }
        $excel_data = TaskService::instance()->parseExcel($post_data['file_path']);
        if(empty($excel_data)){
            $this->error('解析失败');
        }
        if(!is_array($excel_data)){
            $this->error($excel_data);
        }
        unset($excel_data[0]);
        $data = array_values($excel_data);
        foreach ($data as $v){
            $save_data = [
                'task_id'=>$task_id,
                'user_id'=>$this->user_id,
                'video_title'=>$v[0],
                'video_content'=>$v[1],
                'video_keywords'=>$v[2],
                'ai_gaixie_content'=>$v[3],
                'emotion'=>$v[4],
                'gaixie_status'=>2,
                'filter_status'=>1
            ];
            RedianData::mk()->insert($save_data);
        }
        // dump($schedule);exit;

        $this->success('创建成功',$task_id);
    }


    public function getList()
    {
        $list = RedianTask::mk()->where(['user_id'=>$this->user_id])->order('id desc')->select()->toArray();
        foreach ($list as &$v){
            // 将多行文本按换行符分割成数组
            $remarkLines = explode("\n", $v['keywords']);
            // 去除每一行的前后空格
            $remarkLines = array_map('trim', $remarkLines);
            // 去除空行
            $remarkLines = array_filter($remarkLines, function($line) {
                return !empty($line);
            });
            $v['keywords'] = $remarkLines;
        }
        $this->success('获取成功', $list);

    }


    //开始任务
    public function startTask()
    {

        $task_id = input('task_id');
        $error_status = RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->value('error_status');
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>$error_status,'error_status'=>0]);
        $code = sysqueue("热点转换任务", "xbase:taskRun", $later = 0, $data = [
            'task_id'=>$task_id,
        ], $rscript = 1, $loops = 0);
        $this->success("任务创建成功",$code);



        $task = RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->find();
        TaskService::instance()->videoStatus($task);exit;
        $redian_data = TaskService::instance()->videoGenerate($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:视频生成失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }
        exit;
        $redian_data = TaskService::instance()->textGenerate($task);exit;
        if(empty($task)){
            $this->error('任务不存在');
        }
        //开始采集任务
        dump("开始采集任务");
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>1]);
        $redian_data = TaskService::instance()->startGather($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:采集失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }

        //计算相似度
        dump("计算相似度");
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>2]);
        $redian_data = TaskService::instance()->similarity($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:相似度计算失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }
        $out_redian_data = RedianData::mQuery()->where(['task_id'=>$task_id])->order('similarity desc')->limit(0,$task['out_num'])->select()->toArray();
        $out_redian_data_ids = array_column($out_redian_data,'id');
        RedianData::mQuery()->whereIn('id',$out_redian_data_ids)->update(['filter_status'=>1]);
        //口播文本生成
        dump("口播文本生成");
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>3]);
        $redian_data = TaskService::instance()->textGenerate($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:口播文本生成失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }
        //音频生成
        dump("音频生成");
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>4]);
        $redian_data = TaskService::instance()->audioGenerate($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:音频生成失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }
        //视频生成
        dump("视频生成");
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>5]);
        $redian_data = TaskService::instance()->videoGenerate($task);
        if(empty($redian_data)){
            $this->error('任务执行失败:视频生成失败');
            RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->update(['progress'=>7]);
        }
        //创建视频生成状态查询任务
        $this->success('操作成功', $redian_data);




    }

    //删除任务
    public function delTask()
    {
        $task_id = input('task_id');
        $task = RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->find();
        if(empty($task)){
            $this->error('任务不存在');
        }
        RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->delete();
        RedianData::mQuery()->where(['task_id'=>$task_id])->delete();
    }


    //任务详情
    public function getInfo()
    {
        $task_id = input('task_id');
        $task = RedianTask::mQuery()->where(['user_id'=>$this->user_id,"id"=>$task_id])->find();
        if(empty($task)){
            $this->error('任务不存在');
        }
        // 将多行文本按换行符分割成数组
        $remarkLines = explode("\n", $task['keywords']);
        // 去除每一行的前后空格
        $remarkLines = array_map('trim', $remarkLines);
        // 去除空行
        $remarkLines = array_filter($remarkLines, function($line) {
            return !empty($line);
        });
        $task['keywords'] = $remarkLines;
        if($task['push_schedule']){
            $task['push_schedule_arr'] = json_decode($task['push_schedule'],true);
        }else{
            $task['push_schedule_arr'] = [];
        }
        $this->success('操作成功', $task);
    }

    //获取任务热点数据
    public function getData()
    {
        $task_id = input('task_id');
        $page= input('page',1);
        $page_size = input('page_size',20);
        $redian_data = RedianData::mQuery()->where(['task_id'=>$task_id])
            ->order('filter_status desc,similarity desc,time desc,id desc')->page($page,false,false,$page_size);
        foreach ($redian_data['list'] as &$v){
            $v['time'] = date('Y-m-d H:i:s',$v['time']);
            $v['description'] = strip_tags(htmlspecialchars_decode($v['description']));
        }
        $this->success('操作成功', $redian_data);
    }

    //任务数据统计
    public function getDataCount()
    {
        //成功转化数量
        $task_id = input('task_id');
        $aigaixu_count = RedianData::mQuery()
            ->where([
                'task_id'=>$task_id,
                'gaixie_status'=>2,
            ])->whereNotNull("ai_gaixie_content")
            ->count();
        $audio_count = RedianData::mQuery()
            ->where([
                'task_id'=>$task_id,
                'audio_status'=>3,
            ])->whereNotNull("audio_url")
            ->count();
        $success_count = RedianData::mQuery()
            ->where([
                'task_id'=>$task_id,
                'video_status'=>3,
            ])->whereNotNull("video_url")
            ->count();
        $this->success('操作成功', ['aigaixu_count'=>$aigaixu_count,'audio_count'=>$audio_count,'success_count'=>$success_count]);
    }









    //开始采集任务
    public function startGather()
    {
        $task_id = input('task_id');
        $task = RedianTask::mk()->find($task_id);
        if(empty($task)){
            $this->error('任务不存在');
        }
        $num = $task['num'];
        $pages = ceil($num/50);
        $list = [];
        for($i=1;$i<=$pages;$i++){
            $res = TophubdataService::instance()->search($this->user_id,$task['keywords'],$i);
           // dump($res);
            if($res['code']==0){
                $this->error($res['msg']);
            }else{
               // $res = $res['data'];
                $list = array_merge($list,$res['data']['items']);
            }
        }
        foreach ($list as $k=>$v){
            $data = [
                'task_id'=>$task_id,
                'title'=>$v['title'],
                'url'=>$v['url'],
                'description'=>$v['description'],
                'thumbnail'=>$v['thumbnail'],
                'extra'=>$v['extra'],
                'time'=>$v['time'],
            ];
            RedianData::mk()->insert($data);
        }
        $this->success('获取成功', $list);

    }

    //口播文本生成
    public function textGenerate()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        foreach ($redian_data as &$v){
            $user_content = str_replace( ['{{标题}}', '{{描述}}'], [$v['title'], $v['description']], $data['user_content']);
            $system_content = $data['system_content'];
            $res = AlibailianService::instance()->createText($this->user_id,$system_content,$user_content);
            if(isset($res['choices'][0]['message']['content'])){
                $v['ai_gaixie_content'] = $res['choices'][0]['message']['content'];
                $v['gaixie_status'] = 2;
            }else{
                $v['ai_gaixie_content'] = '改写失败:'.$res['message'];
                $v['gaixie_status'] = 3;
            }
            RedianData::mk()->where(['id'=>$v['id']])->save($v);
        }
        $this->success('操作成功', $redian_data);


    }

    //音频生成
    public function audioGenerate()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        foreach ($redian_data as &$v){
            if(empty($v['ai_gaixie_content'])){
                $v['audio_errmsg'] = "口播文本未生成";
                $v['audio_status'] = 4;
            }else{
                $res = HuoshanService::instance()->createAudio($this->user_id,$v['ai_gaixie_content']);
                if(isset($res['task_id'])){
                    $v['audio_id'] = $res['task_id'];
                    $v['audio_status'] = 2;
                    $v['audio_errmsg'] = null;
                }else{
                    $v['audio_errmsg'] = $res['message'];
                    $v['audio_status'] = 4;
                }
            }

            RedianData::mk()->where(['id'=>$v['id']])->save($v);
        }
        $this->success('操作成功', $redian_data);
    }

    //查询音频状态
    public function audioStatus()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        $this->success('操作成功', $redian_data);
    }



    //视频生成
    public function videoGenerate()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        foreach ($redian_data as &$v){
            if(empty($v['audio_url'])){
                $v['video_errmsg'] = "口播音频未生成";
                $v['video_status'] = 4;
            }else{
                $res = HeygenService::instance()->createVideo($this->user_id,$v['audio_url']);
               // dump($res);
                if(isset($res['data']['video_id'])){
                    $v['video_id'] = $res['data']['video_id'];
                    $v['video_status'] = 2;
                    $v['video_errmsg'] = null;
                    $v['video_url'] = null;
                    $v['video_url_caption'] = null;
                    $v['video_data'] = null;

                }else{
                    $v['video_errmsg'] = $res['error']['message'];
                    $v['video_status'] = 4;
                }
            }

            RedianData::mk()->where(['id'=>$v['id']])->save($v);

        }
        $this->success('操作成功', $redian_data);
    }

    //查询视频状态
    public function videoStatus()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        foreach ($redian_data as &$v){
            if(!empty($v['video_id'])){
                $res = HeygenService::instance()->getVideoStatus($this->user_id,$v['video_id']);
                dump($res);exit;
                if(isset($res['data']['video_url'])){
                    $v['video_url'] = $res['data']['video_url'];
                    $v['video_status'] = 3;
                    $v['video_errmsg'] = null;
                    $v['video_url_caption'] = $res['data']['video_url_caption'];
                    $v['video_data'] = json_encode($res['data']);
                    RedianData::mk()->where(['id'=>$v['id']])->save($v);
                }else{
                    $v['video_heygen_data'] = $res;
                }
            }
        }
        $this->success('操作成功', $redian_data);
    }

    //查询Heygen上的视频模板列表
    public function getVideoTemplateList()
    {
        $list = HeygenService::instance()->getVideoTemplate($this->user_id);
        $this->success('获取成功', $list);
    }


    //Minimax音频生成
    public function minimaxAudioGenerate()
    {
        $data = $this->app->request->post();
        $redian_data = RedianData::mQuery()->whereIn('id',$data['redian_ids'])->select()->toArray();
        foreach ($redian_data as &$v){
            if(empty($v['ai_gaixie_content'])){
                $v['audio_errmsg'] = "口播文本未生成";
                $v['audio_status'] = 4;
            }else{
                $res = MinimaxService::instance()->createVoiceFile($this->user_id,$v['ai_gaixie_content']);
                $this->success("success", $res);
            }

        }
    }
    //Minimax音频状态查询
    public function minimaxAudioStatus()
    {
       $task_id = input('task_id');
        $res = MinimaxService::instance()->getVoiceStatus($this->user_id,$task_id);
        dump($res);
    }
    //Minimax音频下载地址
    public function getminimaxAudio()
    {
        $file_id = input('file_id');
        $res = MinimaxService::instance()->getVoice($this->user_id,$file_id);
        dump($res);
    }

    //影刀任务数据
    public function getTaskData()
    {
        $list = RedianTask::mk()->where(['user_id'=>$this->user_id,'yd_is'=>0,'progress'=>6])
            ->field("id,user_id,title,code,keywords")
            ->order('id desc')->find();
        $data = RedianData::mk()->field("title,video_url")->whereNotNull('video_url')->where(['task_id'=>$list['id']])->select()->toArray();
        $this->success('获取成功', $data);

    }


    //相似度计算
    public function similarity()
    {
        $task_id = input('id');
        dump($task_id);
        $keywords = RedianTask::mQuery()->where(['id'=>$task_id])->value('keywords');
        dump($keywords);
        $redian_data = RedianData::mQuery()->field("title,description")->where(['task_id'=>$task_id])->limit(0,5)->select()->toArray();
        foreach ($redian_data as &$v){
            $content = $v['title'];
            if($v['description']){
                //清除html代码
                dump($v['description']);
                $content.=strip_tags(htmlspecialchars_decode($v['description']));
                dump($content);
            }
            $v['similarity'] = SimilarityService::instance()->similarity($keywords,$content);
        }
        dump($redian_data);

    }


    public function cmp()
    {
        dump($this->app->request->domain().'/mp3/audio.mp3');exit;


    }


    //获取热点数据详情
    public function getHotData()
    {
        $id = input('id');
        $data = RedianData::mk()->where(['id'=>$id])->find();
        RedianData::mk()->where(['id'=>$id])->save(['is_receive'=>1]);
        $this->success('获取成功', $data);

    }

    public function updateData()
    {
        $data = $this->app->request->get();
        RedianData::mk()->where(['id'=>$data['id']])->save($data);
        $this->success('更新成功');
    }








}
